//
//  ManagementAddressCell.m
//  hnGovernment
//
//  Created by 安仔 on 17/3/8.
//  Copyright © 2017年 安仔. All rights reserved.
//

#import "ManagementAddressCell.h"
#import "DDcacheManager.h"
@interface ManagementAddressCell ()
@property (nonatomic, strong) UIView *lineView;
@end

@implementation ManagementAddressCell

- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self.contentView addSubview:self.selectedBtn];
        [self.contentView addSubview:self.signLab];
        [self.contentView addSubview:self.deleteBtn];
        [self.contentView addSubview:self.editBtn];
        [self.contentView addSubview:self.lineView];
        [self.contentView addSubview:self.nameLab];
        [self.contentView addSubview:self.phoneLab];
        [self.contentView addSubview:self.addressLab];
    }
    return self;
}

#pragma mark -- 代理
- (void)clickSelectedBtn {
    if ([self.delegate respondsToSelector:@selector(ManagementAddressCellClickSelectedBtn)]) {
        [self.delegate ManagementAddressCellClickSelectedBtn];
    }
}

- (void)clickDeleteBtn {
    if ([self.delegate respondsToSelector:@selector(ManagementAddressCellClickDeleteBtn)]) {
        [self.delegate ManagementAddressCellClickDeleteBtn];
    }
}

- (void)clickEditBtn {
    if ([self.delegate respondsToSelector:@selector(ManagementAddressCellClickDeleteBtn)]) {
        [self.delegate ManagementAddressCellClickDeleteBtn];
    }
}


- (void) layoutSubviews {

    [super layoutSubviews];
    
    [self.selectedBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).offset(34 * m6Scale);
        make.top.mas_equalTo(self.contentView.mas_top).offset(30 * m6Scale);
        make.size.mas_equalTo(CGSizeMake(40 * m6Scale, 40 * m6Scale));
    }];
    
    [self.signLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.selectedBtn.mas_right).offset(15 * m6Scale);
        make.centerY.mas_equalTo(self.selectedBtn.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(170 * m6Scale, 36 * m6Scale));
    }];
    
    [self.deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.selectedBtn.centerY);
        make.right.mas_equalTo(self.contentView.mas_right).offset(-30 * m6Scale);
        make.size.mas_equalTo(CGSizeMake(34 * m6Scale, 32 * m6Scale));
    }];
    
    [self.editBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.selectedBtn.centerY);
        make.right.mas_equalTo(self.deleteBtn.mas_left).offset(-18 * m6Scale);
        make.size.mas_equalTo(CGSizeMake(34 * m6Scale, 32 * m6Scale));
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left);
        make.top.mas_equalTo(self.contentView.mas_top).offset(88 * m6Scale);
        make.size.mas_equalTo(CGSizeMake(KScreenWidth, 2 * m6Scale));
    }];
    
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.selectedBtn.mas_left);
        make.top.mas_equalTo(self.contentView.mas_top).offset(114 * m6Scale);
        make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-80 * m6Scale);
    }];
    
    [self.phoneLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.contentView.mas_right).offset(-32 * m6Scale);
        make.top.mas_equalTo(self.contentView.mas_top).offset(114 * m6Scale);
        make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-80 * m6Scale);
    }];
    
    [self.addressLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.selectedBtn.mas_left);
        make.top.mas_equalTo(self.contentView.mas_top).offset(170 * m6Scale);
        make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-24 * m6Scale);
    }];

}

- (UILabel *)addressLab {
    
    if (!_addressLab) {
        _addressLab = [[UILabel alloc] init];
        _addressLab.text = NSLocalString(@"河南省郑州市中原区建设路12号");
        _addressLab.textColor = RGB(103, 103, 103);
        _addressLab.font = [UIFont systemFontOfSize:28 * m6Scale];
        _addressLab.textAlignment = NSTextAlignmentLeft;
    }
    return _addressLab;
}

- (UILabel *)phoneLab {
    
    if (!_phoneLab) {
        _phoneLab = [[UILabel alloc] init];
        _phoneLab.text = NSLocalString(@"18645867834");
        _phoneLab.textColor = RGB(103, 103, 103);
        _phoneLab.font = [UIFont systemFontOfSize:28 * m6Scale];
        _phoneLab.textAlignment = NSTextAlignmentRight;
    }
    return _phoneLab;
}

- (UILabel *)nameLab {

    if (!_nameLab) {
        _nameLab = [[UILabel alloc] init];
//        NSString *title = [NSString stringWithFormat:@"当前昵称：%@",[cacheManager getUserModel].displayName];
//        _nameLab.text = NSLocalString(title);
        _nameLab.textColor = RGB(103, 103, 103);
        _nameLab.font = [UIFont systemFontOfSize:28 * m6Scale];
    }
    return _nameLab;
}

- (UIView *)lineView {

    if (!_lineView) {
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = BackgroundColor;
    }
    return _lineView;
}

- (UIButton *)editBtn {
    
    if (!_editBtn) {
        _editBtn = [[UIButton alloc] init];
        [_editBtn setImage:[UIImage imageNamed:@"修改地址"] forState:0];
        [_editBtn addTarget:self action:@selector(clickEditBtn) forControlEvents:UIControlEventTouchUpInside];

    }
    return _editBtn;
}

- (UIButton *)deleteBtn {

    if (!_deleteBtn) {
        _deleteBtn = [[UIButton alloc] init];
        [_deleteBtn setImage:[UIImage imageNamed:@"删除地址"] forState:0];
        [_deleteBtn addTarget:self action:@selector(clickDeleteBtn) forControlEvents:UIControlEventTouchUpInside];

    }
    return _deleteBtn;
}

- (UILabel *)signLab {
    
    if (!_signLab) {
        _signLab = [[UILabel alloc] init];
        _signLab.text = NSLocalString(@"设为默认");
        _signLab.textColor = RGB(103, 103, 103);
        _signLab.font = [UIFont systemFontOfSize:28 * m6Scale];
    }
    return _signLab;
}

- (UIButton *)selectedBtn {

    if (!_selectedBtn) {
        _selectedBtn = [[UIButton alloc] init];
        [_selectedBtn setImage:[UIImage imageNamed:@"未选择"] forState:0];
        [_selectedBtn setImage:[UIImage imageNamed:@"删除地址"] forState:UIControlStateSelected];
        [_selectedBtn addTarget:self action:@selector(clickSelectedBtn) forControlEvents:UIControlEventTouchUpInside];
    }
    return _selectedBtn;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
